#ifndef _GRANDIAX_MANAEGG_LIVE_SF_MODIFIER_
#define _GRANDIAX_MANAEGG_LIVE_SF_MODIFIER_

#include <Windows.h>


typedef struct MANAEGG_INTERNAL_DATA
{
    unsigned char Egg;
    unsigned char Unknown;
    unsigned char AttachSlot;
    unsigned char Attacher;

    unsigned short MpMax;
    unsigned short Mp;

    unsigned short Magic[6];

    unsigned char  SF[6];

    unsigned char  Starts[2];

} MANAEGG_INTERNAL_DATA;


typedef struct MAGIC_INTERNAL_DATA_UNIT
{
    unsigned short MP;
    unsigned short Zero;

    unsigned short IpRestore;
    unsigned short Zero1;

    unsigned long Zero2;

    unsigned short Width;
    unsigned short Duration; // Com-->Launch, Not Effect Lasting Time!

    unsigned long Effect;
    unsigned long One;
} MAGIC_INTERNAL_DATA_UNIT;

typedef union MAGIC_INTERNAL_DATA
{
    MAGIC_INTERNAL_DATA_UNIT AsArray[4];
    struct 
    {
        MAGIC_INTERNAL_DATA_UNIT Main;
        MAGIC_INTERNAL_DATA_UNIT Extended;
        MAGIC_INTERNAL_DATA_UNIT Star;
        MAGIC_INTERNAL_DATA_UNIT StarExt;
    } Desc;
} MAGIC_INTERNAL_DATA;   


typedef struct EFFECT_INTERNAL_DATA_UNIT
{
    unsigned char Function;// *1 OK bit0: Set/Clear Status/State Bit, HP/MP/SP++, ...
    unsigned char FunctionFixer; // For Fixing Loaded Data
    unsigned short Hit; // Not Editable

    unsigned short Power; // *2 OK
    unsigned short Timer; // Not Editable

    unsigned short Lasting; // *2, OK
    unsigned short Ip; // *2, OK, Cross!!

    unsigned short CancelIp; 
    unsigned short KnockBack; // *1 OK

    unsigned short Status; // *1 OK
    unsigned short Zero;

    unsigned short Rate; // *2 OK 0~0x64 (0~100%)
    unsigned char Element; // *1 OK
    unsigned char States; // *1 OK

    unsigned char Special; // *1 OK, unsigned char
    unsigned char Zero1; // *1 OK, unsigned char
    unsigned short Zero2; // *1 OK, unsigned char
} EFFECT_INTERNAL_DATA_UNIT;


typedef union EFFECT_INTERNAL_DATA
{
    EFFECT_INTERNAL_DATA_UNIT AsArray[4];
    struct 
    {
        EFFECT_INTERNAL_DATA_UNIT Main;
        EFFECT_INTERNAL_DATA_UNIT Extended;
        EFFECT_INTERNAL_DATA_UNIT Star;
        EFFECT_INTERNAL_DATA_UNIT StarExt;
    } Desc;
} EFFECT_INTERNAL_DATA;   

typedef struct SKILL_BOOK
{
    unsigned char Rank;
    unsigned char Capacity;
    unsigned short Cost;
} SKILL_BOOK;

typedef struct MANAEGG_INTERNAL_TABLE
{
    unsigned short Magics[6];
    unsigned short Unresearched[24];
} MANAEGG_INTERNAL_TABLE;

typedef struct BATTLE_ITEM_DATA
{
    unsigned short Item;
    unsigned short Count;
} BATTLE_ITEM_DATA;

typedef unsigned char PARTY_DATA;

typedef struct SPECIAL_HEADER
{
    unsigned char Selection;
    unsigned char Target;
    unsigned char Area; // Single=1/Circle/Line/Fan/All/Arround! 
    unsigned char Reserved;

    unsigned short Zeros;
    unsigned char Element;// Fire/Water.... on Weapon
    unsigned char Levels; // how many stars of the special

    unsigned long DefPtr; // Pointer to the definition

    unsigned char TextLen[4]; // Length to the followin strings

    unsigned long NamePtr; // Point to the name
    unsigned long DescPtr; // Point to the Description1
    unsigned long DescPtr2; // Point to the Description1

    unsigned char Party[4]; // Combi Party
} SPECIAL_HEADER;


typedef struct SPECIAL_DEF
{
    unsigned short Zeros;
    unsigned short SP; // Once

    unsigned short IpRestore; // *Levels
    unsigned short Zeros1;

    unsigned long Zeros2;

    unsigned short Width; // *Levels
    unsigned short LaunchTime; // *Levels

    unsigned long DetailPtr;

    unsigned long Acts; //01 or 02
} SPECIAL_DEF;


typedef struct SPECIAL_DETAIL
{
    unsigned char Function; // Once, 0~7, +HP,+MP, ect, ...
    unsigned char EffectFlag; // *Acts, Set when Effect Active, Can be ignored
    unsigned short Reserved;

    unsigned short Level; // *Acts + Level
    unsigned short Timer; // Not Editable

    unsigned short Lasting; // *Acts + Level
    unsigned short Ip; // *Acts + Level

    unsigned short CancelIp; // *Acts + Level, Magic might add this!!
    unsigned short KnockBack; // *Acts

    unsigned short Status; // *Acts
    unsigned short Zero;

    unsigned short Rate; // *Acts + Level
    unsigned char Element; // Once
    unsigned char States; // *Acts

    unsigned char Special; // *Acts
    unsigned char Zero1;
    unsigned short Zero2;
} SPECIAL_DETAIL;

typedef struct MOVE_SKILLUP
{
    unsigned long Index;

    unsigned short LevelUp[6];

    char RefMove[2];
    char RefLevel[2];

    unsigned short Level;
    unsigned short Star;
} MOVE_SKILLUP;


bool GrandiaXLiveModifierActive();

void GrandiaXLiveModifierExit();

bool GrandiaXLiveModifierIsActive();

// Instant Write
void GrandiaXLiveModifierWrite(SPECIAL_HEADER* Header, MAGIC_INTERNAL_DATA* Def, EFFECT_INTERNAL_DATA* Detail);

void GrandiaXLiveModifierWrite(SKILL_BOOK* Data);

void GrandiaXLiveModifierWrite(MANAEGG_INTERNAL_TABLE* Data);

void GrandiaXLiveModifierWrite(MANAEGG_INTERNAL_DATA* Data);

void GrandiaXLiveModifierWrite(BATTLE_ITEM_DATA* Data);

void GrandiaXLiveModifierWrite(MOVE_SKILLUP* SkillUp,
    SPECIAL_HEADER* Header, SPECIAL_DEF* Def, SPECIAL_DETAIL* Details);

void GrandiaXLiveModifierWrite(PARTY_DATA* Data);

// Instant Read
void GrandiaXLiveModifierRead(SPECIAL_HEADER* Header, MAGIC_INTERNAL_DATA* Def, EFFECT_INTERNAL_DATA* Detail);

void GrandiaXLiveModifierRead(SKILL_BOOK* Data);

void GrandiaXLiveModifierRead(MANAEGG_INTERNAL_TABLE* Data);

bool GrandiaXLiveModifierRead(MANAEGG_INTERNAL_DATA* Data);

bool GrandiaXLiveModifierRead(BATTLE_ITEM_DATA* Data);

void GrandiaXLiveModifierRead(MOVE_SKILLUP* SkillUp,
    SPECIAL_HEADER* Header, SPECIAL_DEF* Def, SPECIAL_DETAIL* Details);

bool GrandiaXLiveModifierRead(PARTY_DATA* Data);

// For Develop
bool GrandiaXLiveModifierRead(void* Buffer, int Start, int Length);

#endif
